package com.market.entity.dto;

import com.market.entity.base.Fruit;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Data
@AllArgsConstructor
public class OrderDto {
   private final Map<Fruit, BigDecimal> items;

   public OrderDto() {
      items = new HashMap<>();
   }

   public void addItem(Fruit fruit, BigDecimal weight) {
      if (weight.compareTo(BigDecimal.ZERO) < 0) {
         throw new IllegalArgumentException("重量不能为负数");
      }
      items.merge(fruit, weight, BigDecimal::add);
   }
}
